
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>4.ESlint 检测规则说明 · 邦德前端开发</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        <meta name="author" content="i@ickeep.com">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-diy-introduction/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5.vue规范.html" />
    
    
    <link rel="prev" href="3.JavaScript.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://2017hcb.bond520.com/pc/index.html" target="_blank" class="custom-link">邦德官网</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">开发说明</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">前端规范</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="1.HTML.html">
            
                <a href="1.HTML.html">
            
                    
                    1.HTML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="2.CSS.html">
            
                <a href="2.CSS.html">
            
                    
                    2.CSS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="3.JavaScript.html">
            
                <a href="3.JavaScript.html">
            
                    
                    3.JavaScript
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.4" data-path="4.ESlint检测规则说明.html">
            
                <a href="4.ESlint检测规则说明.html">
            
                    
                    4.ESlint 检测规则说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="5.vue规范.html">
            
                <a href="5.vue规范.html">
            
                    
                    5.vue规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="6.前后端数据交互说明.html">
            
                <a href="6.前后端数据交互说明.html">
            
                    
                    6.前后端数据交互说明
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">常见问题</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../3.常见问题/常见问题.html">
            
                <a href="../3.常见问题/常见问题.html">
            
                    
                    常见问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >4.ESlint 检测规则说明</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="eslint&#x68C0;&#x6D4B;&#x89C4;&#x5219;&#x8BF4;&#x660E;"><a name="eslint&#x68C0;&#x6D4B;&#x89C4;&#x5219;&#x8BF4;&#x660E;" class="plugin-anchor" href="#eslint&#x68C0;&#x6D4B;&#x89C4;&#x5219;&#x8BF4;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>ESlint&#x68C0;&#x6D4B;&#x89C4;&#x5219;&#x8BF4;&#x660E;</h1>
<blockquote>
<p>&#x53C2;&#x8003; <a href="https://github.com/yuche/javascript/blob/master/README.md" target="_blank">Airbnb JavaScript Style Guide &#x4E2D;&#x6587;&#x7248;</a>
&#x505A;&#x4E86;&#x4E00;&#x5B9A;&#x7684;&#x4FEE;&#x6539;&#xFF0C;&#x5927;&#x91CF;&#x9519;&#x8BEF;&#x6539;&#x4E3A;&#x8B66;&#x544A;&#x65B9;&#x4FBF;&#x8C03;&#x8BD5;
&#x5B57;&#x7B26;&#x4E32;&#x53CC;&#x5F15;&#x53F7;&#x6539;&#x4E3A;&#x5355;&#x5F15;&#x53F7;&#xFF08;&#x4E3A;&#x4E86;&#x8DDF;HTML&#x5C5E;&#x6027;&#x533A;&#x5206;&#xFF09;
&#x53BB;&#x6389;&#x5206;&#x53F7;</p>
</blockquote>
<h2 id="&#x7C7B;&#x578B;"><a name="&#x7C7B;&#x578B;" class="plugin-anchor" href="#&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7C7B;&#x578B;</h2>
<ul>
<li><p><a href="#1.1">1.1</a> <a name="1.1"></a> <strong>&#x57FA;&#x672C;&#x7C7B;&#x578B;</strong>: &#x76F4;&#x63A5;&#x5B58;&#x53D6;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x3002;</p>
<ul>
<li><code>&#x5B57;&#x7B26;&#x4E32;</code></li>
<li><code>&#x6570;&#x503C;</code></li>
<li><code>&#x5E03;&#x5C14;&#x7C7B;&#x578B;</code></li>
<li><code>null</code></li>
<li><code>undefined</code></li>
</ul>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span>
<span class="token keyword">let</span> bar <span class="token operator">=</span> foo

bar <span class="token operator">=</span> <span class="token number">9</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>foo<span class="token punctuation">,</span> bar<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; 1, 9</span>
</code></pre>
</li>
<li><p><a href="#1.2">1.2</a> <a name="1.2"></a> <strong>&#x590D;&#x6742;&#x7C7B;&#x578B;</strong>: &#x901A;&#x8FC7;&#x5F15;&#x7528;&#x7684;&#x65B9;&#x5F0F;&#x5B58;&#x53D6;&#x590D;&#x6742;&#x7C7B;&#x578B;&#x3002;</p>
<ul>
<li><code>&#x5BF9;&#x8C61;</code></li>
<li><code>&#x6570;&#x7EC4;</code></li>
<li><code>&#x51FD;&#x6570;</code></li>
</ul>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span>
<span class="token keyword">const</span> bar <span class="token operator">=</span> foo

bar<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">9</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>foo<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> bar<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; 9, 9</span>
</code></pre>
</li>
</ul>
<h2 id="&#x5F15;&#x7528;"><a name="&#x5F15;&#x7528;" class="plugin-anchor" href="#&#x5F15;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F15;&#x7528;</h2>
<ul>
<li><p><a href="#2.1">2.1</a> <a name="2.1"></a> &#x5BF9;&#x6240;&#x6709;&#x7684;&#x5F15;&#x7528;&#x4F7F;&#x7528; <code>const</code> &#xFF1B;&#x4E0D;&#x8981;&#x4F7F;&#x7528; <code>var</code>&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x80FD;&#x786E;&#x4FDD;&#x4F60;&#x65E0;&#x6CD5;&#x5BF9;&#x5F15;&#x7528;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5BFC;&#x81F4;&#x51FA;&#x73B0; bug &#x6216;&#x96BE;&#x4EE5;&#x7406;&#x89E3;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">1</span>
<span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token number">2</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> a <span class="token operator">=</span> <span class="token number">1</span>
<span class="token keyword">const</span> b <span class="token operator">=</span> <span class="token number">2</span>
</code></pre>
</li>
<li><p><a href="#2.2">2.2</a> <a name="2.2"></a> &#x5982;&#x679C;&#x4F60;&#x4E00;&#x5B9A;&#x9700;&#x8981;&#x53EF;&#x53D8;&#x52A8;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x4F7F;&#x7528; <code>let</code> &#x4EE3;&#x66FF; <code>var</code>&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;  <code>let</code> &#x662F;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x800C; <code>var</code> &#x662F;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">var</span> count <span class="token operator">=</span> <span class="token number">1</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  count <span class="token operator">+</span><span class="token operator">=</span> <span class="token number">1</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good, use the let.</span>
<span class="token keyword">let</span> count <span class="token operator">=</span> <span class="token number">1</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  count <span class="token operator">+</span><span class="token operator">=</span> <span class="token number">1</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#2.3">2.3</a> <a name="2.3"></a> &#x6CE8;&#x610F; <code>let</code> &#x548C; <code>const</code> &#x90FD;&#x662F;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// const &#x548C; let &#x53EA;&#x5B58;&#x5728;&#x4E8E;&#x5B83;&#x4EEC;&#x88AB;&#x5B9A;&#x4E49;&#x7684;&#x533A;&#x5757;&#x5185;&#x3002;</span>
<span class="token punctuation">{</span>
  <span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">1</span>
  <span class="token keyword">const</span> b <span class="token operator">=</span> <span class="token number">1</span>
<span class="token punctuation">}</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ReferenceError</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ReferenceError</span>
</code></pre>
</li>
</ul>
<h2 id="&#x5BF9;&#x8C61;"><a name="&#x5BF9;&#x8C61;" class="plugin-anchor" href="#&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5BF9;&#x8C61;</h2>
<ul>
<li><p><a href="#3.1">3.1</a> <a name="3.1"></a> &#x4F7F;&#x7528;&#x5B57;&#x9762;&#x503C;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> item <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Object</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> item <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#3.2">3.2</a> <a name="3.2"></a> &#x5982;&#x679C;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x4E0B;&#x6267;&#x884C;&#xFF0C;&#x522B;&#x4F7F;&#x7528; <a href="http://es5.github.io/#x7.6.1" target="_blank">&#x4FDD;&#x7559;&#x5B57;</a> &#x4F5C;&#x4E3A;&#x952E;&#x503C;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#x5728; IE8 &#x4E0D;&#x4F1A;&#x8FD0;&#x884C;&#x3002; <a href="https://github.com/airbnb/javascript/issues/61" target="_blank">&#x66F4;&#x591A;&#x4FE1;&#x606F;</a>&#x3002; &#x4F46;&#x5728; ES6 &#x6A21;&#x5757;&#x548C;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x4E2D;&#x4F7F;&#x7528;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> superman <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token keyword">default</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> clark<span class="token punctuation">:</span> <span class="token string">&apos;kent&apos;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token keyword">private</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> superman <span class="token operator">=</span> <span class="token punctuation">{</span>
  defaults<span class="token punctuation">:</span> <span class="token punctuation">{</span> clark<span class="token punctuation">:</span> <span class="token string">&apos;kent&apos;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  hidden<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#3.3">3.3</a> <a name="3.3"></a> &#x4F7F;&#x7528;&#x540C;&#x4E49;&#x8BCD;&#x66FF;&#x6362;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x4FDD;&#x7559;&#x5B57;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> superman <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token keyword">class</span><span class="token punctuation">:</span> <span class="token string">&apos;alien&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> superman <span class="token operator">=</span> <span class="token punctuation">{</span>
  klass<span class="token punctuation">:</span> <span class="token string">&apos;alien&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> superman <span class="token operator">=</span> <span class="token punctuation">{</span>
  type<span class="token punctuation">:</span> <span class="token string">&apos;alien&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<ul>
<li><p><a href="#3.4">3.4</a> <a name="3.4"></a> &#x521B;&#x5EFA;&#x6709;&#x52A8;&#x6001;&#x5C5E;&#x6027;&#x540D;&#x7684;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x53EF;&#x88AB;&#x8BA1;&#x7B97;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x79F0;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x8BA9;&#x4F60;&#x5728;&#x4E00;&#x4E2A;&#x5730;&#x65B9;&#x5B9A;&#x4E49;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x3002;</p>
</blockquote>
<p><code>``javascript
function getKey(k) {
  return</code>a key named ${k}`
}</p>
<p>// bad
const obj = {
  id: 5,
  name: &apos;San Francisco&apos;,
}
obj[getKey(&apos;enabled&apos;)] = true</p>
<p>// good
const obj = {
  id: 5,
  name: &apos;San Francisco&apos;,</p>
</li>
</ul>
<pre class="language-"><code>  [getKey(&apos;enabled&apos;)]: true,
}
```
</code></pre><ul>
<li><p><a href="#3.5">3.5</a> <a name="3.5"></a> &#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x7B80;&#x5199;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> atom <span class="token operator">=</span> <span class="token punctuation">{</span>
  value<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>

  addValue<span class="token punctuation">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> atom<span class="token punctuation">.</span>value <span class="token operator">+</span> value
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> atom <span class="token operator">=</span> <span class="token punctuation">{</span>
  value<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>

  <span class="token function">addValue</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> atom<span class="token punctuation">.</span>value <span class="token operator">+</span> value
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<ul>
<li><p><a href="#3.6">3.6</a> <a name="3.6"></a> &#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x7B80;&#x5199;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x66F4;&#x77ED;&#x66F4;&#x6709;&#x63CF;&#x8FF0;&#x6027;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> lukeSkywalker <span class="token operator">=</span> <span class="token string">&apos;Luke Skywalker&apos;</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  lukeSkywalker<span class="token punctuation">:</span> lukeSkywalker<span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  lukeSkywalker<span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#3.7">3.7</a> <a name="3.7"></a> &#x5728;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x58F0;&#x660E;&#x524D;&#x628A;&#x7B80;&#x5199;&#x7684;&#x5C5E;&#x6027;&#x5206;&#x7EC4;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x80FD;&#x6E05;&#x695A;&#x5730;&#x770B;&#x51FA;&#x54EA;&#x4E9B;&#x5C5E;&#x6027;&#x4F7F;&#x7528;&#x4E86;&#x7B80;&#x5199;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> anakinSkywalker <span class="token operator">=</span> <span class="token string">&apos;Anakin Skywalker&apos;</span>
<span class="token keyword">const</span> lukeSkywalker <span class="token operator">=</span> <span class="token string">&apos;Luke Skywalker&apos;</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  episodeOne<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  twoJedisWalkIntoACantina<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
  lukeSkywalker<span class="token punctuation">,</span>
  episodeThree<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
  mayTheFourth<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
  anakinSkywalker<span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  lukeSkywalker<span class="token punctuation">,</span>
  anakinSkywalker<span class="token punctuation">,</span>
  episodeOne<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  twoJedisWalkIntoACantina<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
  episodeThree<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
  mayTheFourth<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<h2 id="&#x6570;&#x7EC4;"><a name="&#x6570;&#x7EC4;" class="plugin-anchor" href="#&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6570;&#x7EC4;</h2>
<ul>
<li><p><a href="#4.1">4.1</a> <a name="4.1"></a> &#x4F7F;&#x7528;&#x5B57;&#x9762;&#x503C;&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Array</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
</code></pre>
</li>
<li><p><a href="#4.2">4.2</a> <a name="4.2"></a> &#x5411;&#x6570;&#x7EC4;&#x6DFB;&#x52A0;&#x5143;&#x7D20;&#x65F6;&#x4F7F;&#x7528; Arrary#push &#x66FF;&#x4EE3;&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x3002;</p>
<p>```javascript
const someStack = []</p>
</li>
</ul>
<pre class="language-"><code>// bad
someStack[someStack.length] = &apos;abracadabra&apos;

// good
someStack.push(&apos;abracadabra&apos;)
```
</code></pre><ul>
<li><p><a href="#4.3">4.3</a> <a name="4.3"></a> &#x4F7F;&#x7528;&#x62D3;&#x5C55;&#x8FD0;&#x7B97;&#x7B26; <code>...</code> &#x590D;&#x5236;&#x6570;&#x7EC4;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> len <span class="token operator">=</span> items<span class="token punctuation">.</span>length
<span class="token keyword">const</span> itemsCopy <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
<span class="token keyword">let</span> i

<span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> len<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  itemsCopy<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">=</span> items<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> itemsCopy <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token operator">...</span>items<span class="token punctuation">]</span>
</code></pre>
</li>
<li><p><a href="#4.4">4.4</a> <a name="4.4"></a> &#x4F7F;&#x7528; Array#from &#x628A;&#x4E00;&#x4E2A;&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x6210;&#x6570;&#x7EC4;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> foo <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelectorAll</span><span class="token punctuation">(</span><span class="token string">&apos;.foo&apos;</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> nodes <span class="token operator">=</span> Array<span class="token punctuation">.</span><span class="token keyword">from</span><span class="token punctuation">(</span>foo<span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<p><a name="destructuring"></a></p>
<h2 id="&#x89E3;&#x6784;"><a name="&#x89E3;&#x6784;" class="plugin-anchor" href="#&#x89E3;&#x6784;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x89E3;&#x6784;</h2>
<ul>
<li><p><a href="#5.1">5.1</a> <a name="5.1"></a> &#x4F7F;&#x7528;&#x89E3;&#x6784;&#x5B58;&#x53D6;&#x548C;&#x4F7F;&#x7528;&#x591A;&#x5C5E;&#x6027;&#x5BF9;&#x8C61;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x89E3;&#x6784;&#x80FD;&#x51CF;&#x5C11;&#x4E34;&#x65F6;&#x5F15;&#x7528;&#x5C5E;&#x6027;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">getFullName</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> firstName <span class="token operator">=</span> user<span class="token punctuation">.</span>firstName
  <span class="token keyword">const</span> lastName <span class="token operator">=</span> user<span class="token punctuation">.</span>lastName

  <span class="token keyword">return</span> <span class="token template-string"><span class="token string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>firstName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>lastName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">getFullName</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">{</span> firstName<span class="token punctuation">,</span> lastName <span class="token punctuation">}</span> <span class="token operator">=</span> obj
  <span class="token keyword">return</span> <span class="token template-string"><span class="token string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>firstName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>lastName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// best</span>
<span class="token keyword">function</span> <span class="token function">getFullName</span><span class="token punctuation">(</span><span class="token punctuation">{</span> firstName<span class="token punctuation">,</span> lastName <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token template-string"><span class="token string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>firstName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>lastName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#5.2">5.2</a> <a name="5.2"></a> &#x5BF9;&#x6570;&#x7EC4;&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> first <span class="token operator">=</span> arr<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
<span class="token keyword">const</span> second <span class="token operator">=</span> arr<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> <span class="token punctuation">[</span>first<span class="token punctuation">,</span> second<span class="token punctuation">]</span> <span class="token operator">=</span> arr
</code></pre>
</li>
<li><p><a href="#5.3">5.3</a> <a name="5.3"></a> &#x9700;&#x8981;&#x56DE;&#x4F20;&#x591A;&#x4E2A;&#x503C;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x89E3;&#x6784;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6570;&#x7EC4;&#x89E3;&#x6784;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x589E;&#x52A0;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x6539;&#x53D8;&#x6392;&#x5E8F;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;&#x8C03;&#x7528;&#x65F6;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">processInput</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// then a miracle occurs</span>
  <span class="token keyword">return</span> <span class="token punctuation">[</span>left<span class="token punctuation">,</span> right<span class="token punctuation">,</span> top<span class="token punctuation">,</span> bottom<span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// &#x8C03;&#x7528;&#x65F6;&#x9700;&#x8981;&#x8003;&#x8651;&#x56DE;&#x8C03;&#x6570;&#x636E;&#x7684;&#x987A;&#x5E8F;&#x3002;</span>
<span class="token keyword">const</span> <span class="token punctuation">[</span>left<span class="token punctuation">,</span> __<span class="token punctuation">,</span> top<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">processInput</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">processInput</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// then a miracle occurs</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span> left<span class="token punctuation">,</span> right<span class="token punctuation">,</span> top<span class="token punctuation">,</span> bottom <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// &#x8C03;&#x7528;&#x65F6;&#x53EA;&#x9009;&#x62E9;&#x9700;&#x8981;&#x7684;&#x6570;&#x636E;</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> left<span class="token punctuation">,</span> right <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">processInput</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<p><a name="strings"></a></p>
<h2 id="strings"><a name="strings" class="plugin-anchor" href="#strings"><i class="fa fa-link" aria-hidden="true"></i></a>Strings</h2>
<ul>
<li><p><a href="#6.1">6.1</a> <a name="6.1"></a> &#x5B57;&#x7B26;&#x4E32;&#x4F7F;&#x7528;&#x5355;&#x5F15;&#x53F7; <code>&apos;&apos;</code> &#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token string">&quot;Capt. Janeway&quot;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token string">&apos;Capt. Janeway&apos;</span>
</code></pre>
</li>
<li><p><a href="#6.2">6.2</a> <a name="6.2"></a> &#x5B57;&#x7B26;&#x4E32;&#x8D85;&#x8FC7; 80 &#x4E2A;&#x5B57;&#x8282;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;&#x53F7;&#x6362;&#x884C;&#x3002;</p>
</li>
<li><p><a href="#6.3">6.3</a> <a name="6.3"></a> &#x6CE8;&#xFF1A;&#x8FC7;&#x5EA6;&#x4F7F;&#x7528;&#x5B57;&#x4E32;&#x8FDE;&#x63A5;&#x7B26;&#x53F7;&#x53EF;&#x80FD;&#x4F1A;&#x5BF9;&#x6027;&#x80FD;&#x9020;&#x6210;&#x5F71;&#x54CD;&#x3002;<a href="http://jsperf.com/ya-string-concat" target="_blank">jsPerf</a> &#x548C; <a href="https://github.com/airbnb/javascript/issues/40" target="_blank">&#x8BA8;&#x8BBA;</a>.</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> errorMessage <span class="token operator">=</span> <span class="token string">&apos;This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.&apos;</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> errorMessage <span class="token operator">=</span> <span class="token string">&apos;This is a super long error that was thrown because \
of Batman. When you stop to think about how Batman had anything to do \
with this, you would get nowhere \
fast.&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> errorMessage <span class="token operator">=</span> <span class="token string">&apos;This is a super long error that was thrown because &apos;</span> <span class="token operator">+</span>
  <span class="token string">&apos;of Batman. When you stop to think about how Batman had anything to do &apos;</span> <span class="token operator">+</span>
  <span class="token string">&apos;with this, you would get nowhere fast.&apos;</span>
</code></pre>
<p><a name="es6-template-literals"></a></p>
</li>
<li><p><a href="#6.4">6.4</a> <a name="6.4"></a> &#x7A0B;&#x5E8F;&#x5316;&#x751F;&#x6210;&#x5B57;&#x7B26;&#x4E32;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;&#x4EE3;&#x66FF;&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;&#x66F4;&#x4E3A;&#x7B80;&#x6D01;&#xFF0C;&#x66F4;&#x5177;&#x53EF;&#x8BFB;&#x6027;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">sayHi</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token string">&apos;How are you, &apos;</span> <span class="token operator">+</span> name <span class="token operator">+</span> <span class="token string">&apos;?&apos;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">sayHi</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token string">&apos;How are you, &apos;</span><span class="token punctuation">,</span> name<span class="token punctuation">,</span> <span class="token string">&apos;?&apos;</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">sayHi</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token template-string"><span class="token string">`How are you, </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">?`</span></span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<p><a name="functions"></a></p>
<h2 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="plugin-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x51FD;&#x6570;</h2>
<ul>
<li><p><a href="#7.1">7.1</a> <a name="7.1"></a> &#x4F7F;&#x7528;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4EE3;&#x66FF;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x662F;&#x53EF;&#x547D;&#x540D;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4ED6;&#x4EEC;&#x5728;&#x8C03;&#x7528;&#x6808;&#x4E2D;&#x66F4;&#x5BB9;&#x6613;&#x88AB;&#x8BC6;&#x522B;&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4F1A;&#x628A;&#x6574;&#x4E2A;&#x51FD;&#x6570;&#x63D0;&#x5347;&#xFF08;hoisted&#xFF09;&#xFF0C;&#x800C;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x53EA;&#x4F1A;&#x628A;&#x51FD;&#x6570;&#x7684;&#x5F15;&#x7528;&#x53D8;&#x91CF;&#x540D;&#x63D0;&#x5347;&#x3002;&#x8FD9;&#x6761;&#x89C4;&#x5219;&#x4F7F;&#x5F97;<a href="#arrow-functions">&#x7BAD;&#x5934;&#x51FD;&#x6570;</a>&#x53EF;&#x4EE5;&#x53D6;&#x4EE3;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#7.2">7.2</a> <a name="7.2"></a> &#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;:</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// &#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F; (IIFE)</span>
<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Welcome to the Internet. Please follow me.&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#7.3">7.3</a> <a name="7.3"></a> &#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x5728;&#x4E00;&#x4E2A;&#x975E;&#x51FD;&#x6570;&#x4EE3;&#x7801;&#x5757;&#xFF08;<code>if</code>&#x3001;<code>while</code> &#x7B49;&#xFF09;&#x4E2D;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x628A;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x8D4B;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;&#x6D4F;&#x89C8;&#x5668;&#x5141;&#x8BB8;&#x4F60;&#x8FD9;&#x4E48;&#x505A;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x7684;&#x89E3;&#x6790;&#x8868;&#x73B0;&#x4E0D;&#x4E00;&#x81F4;&#x3002;</p>
</li>
<li><p><a href="#7.4">7.4</a> <a name="7.4"></a> <strong>&#x6CE8;&#x610F;:</strong> ECMA-262 &#x628A; <code>block</code> &#x5B9A;&#x4E49;&#x4E3A;&#x4E00;&#x7EC4;&#x8BED;&#x53E5;&#x3002;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E0D;&#x662F;&#x8BED;&#x53E5;&#x3002;<a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97" target="_blank">&#x9605;&#x8BFB; ECMA-262 &#x5173;&#x4E8E;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x8BF4;&#x660E;</a>&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>currentUser<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">function</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Nope.&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">let</span> test
<span class="token keyword">if</span> <span class="token punctuation">(</span>currentUser<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  test <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Yup.&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#7.5">7.5</a> <a name="7.5"></a> &#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x628A;&#x53C2;&#x6570;&#x547D;&#x540D;&#x4E3A; <code>arguments</code>&#x3002;&#x8FD9;&#x5C06;&#x53D6;&#x4EE3;&#x539F;&#x6765;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x7684; <code>arguments</code> &#x5BF9;&#x8C61;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">nope</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> options<span class="token punctuation">,</span> arguments<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">yup</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> options<span class="token punctuation">,</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>
</code></pre>
<p><a name="es6-rest"></a></p>
</li>
<li><p><a href="#7.6">7.6</a> <a name="7.6"></a> &#x4E0D;&#x8981;&#x4F7F;&#x7528; <code>arguments</code>&#x3002;&#x53EF;&#x4EE5;&#x9009;&#x62E9; rest &#x8BED;&#x6CD5; <code>...</code> &#x66FF;&#x4EE3;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x4F7F;&#x7528; <code>...</code> &#x80FD;&#x660E;&#x786E;&#x4F60;&#x8981;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x3002;&#x53E6;&#x5916; rest &#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x771F;&#x6B63;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x800C; <code>arguments</code> &#x662F;&#x4E00;&#x4E2A;&#x7C7B;&#x6570;&#x7EC4;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">concatenateAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> args <span class="token operator">=</span> Array<span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>slice<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>arguments<span class="token punctuation">)</span>
  <span class="token keyword">return</span> args<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">concatenateAll</span><span class="token punctuation">(</span><span class="token operator">...</span>args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> args<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p><a name="es6-default-parameters"></a></p>
</li>
<li><p><a href="#7.7">7.7</a> <a name="7.7"></a> &#x76F4;&#x63A5;&#x7ED9;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x53D8;&#x5316;&#x7684;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// really bad</span>
<span class="token keyword">function</span> <span class="token function">handleThings</span><span class="token punctuation">(</span>opts<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// &#x4E0D;&#xFF01;&#x6211;&#x4EEC;&#x4E0D;&#x5E94;&#x8BE5;&#x6539;&#x53D8;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x3002;</span>
  <span class="token comment" spellcheck="true">// &#x66F4;&#x52A0;&#x7CDF;&#x7CD5;: &#x5982;&#x679C;&#x53C2;&#x6570; opts &#x662F; false &#x7684;&#x8BDD;&#xFF0C;&#x5B83;&#x5C31;&#x4F1A;&#x88AB;&#x8BBE;&#x5B9A;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</span>
  <span class="token comment" spellcheck="true">// &#x4F46;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x4F1A;&#x9020;&#x6210;&#x4E00;&#x4E9B; Bugs&#x3002;</span>
  <span class="token comment" spellcheck="true">//&#xFF08;&#x8BD1;&#x6CE8;&#xFF1A;&#x4F8B;&#x5982;&#x5F53; opts &#x88AB;&#x8D4B;&#x503C;&#x4E3A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;opts &#x4ECD;&#x7136;&#x4F1A;&#x88AB;&#x4E0B;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x8BBE;&#x5B9A;&#x4E3A;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#x3002;&#xFF09;</span>
  opts <span class="token operator">=</span> opts <span class="token operator">||</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token comment" spellcheck="true">// ...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// still bad</span>
<span class="token keyword">function</span> <span class="token function">handleThings</span><span class="token punctuation">(</span>opts<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>opts <span class="token operator">===</span> <span class="token keyword">void</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    opts <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
  <span class="token comment" spellcheck="true">// ...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">handleThings</span><span class="token punctuation">(</span>opts <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#7.8">7.8</a> <a name="7.8"></a> &#x76F4;&#x63A5;&#x7ED9;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x8D4B;&#x503C;&#x65F6;&#x9700;&#x8981;&#x907F;&#x514D;&#x526F;&#x4F5C;&#x7528;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x8BA9;&#x4EBA;&#x611F;&#x5230;&#x5F88;&#x56F0;&#x60D1;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token number">1</span>
<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">count</span><span class="token punctuation">(</span>a <span class="token operator">=</span> b<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">count</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">// 1</span>
<span class="token function">count</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">// 2</span>
<span class="token function">count</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 3</span>
<span class="token function">count</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">// 3</span>
</code></pre>
</li>
</ul>
<p><a name="arrow-functions"></a></p>
<h2 id="&#x7BAD;&#x5934;&#x51FD;&#x6570;"><a name="&#x7BAD;&#x5934;&#x51FD;&#x6570;" class="plugin-anchor" href="#&#x7BAD;&#x5934;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7BAD;&#x5934;&#x51FD;&#x6570;</h2>
<ul>
<li><p><a href="#8.1">8.1</a> <a name="8.1"></a> &#x5F53;&#x4F60;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;&#x6216;&#x4F20;&#x9012;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#xFF09;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7B26;&#x53F7;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;?&#x56E0;&#x4E3A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x521B;&#x9020;&#x4E86;&#x65B0;&#x7684;&#x4E00;&#x4E2A; <code>this</code> &#x6267;&#x884C;&#x73AF;&#x5883;&#xFF08;&#x8BD1;&#x6CE8;&#xFF1A;&#x53C2;&#x8003; <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions" target="_blank">Arrow functions - JavaScript | MDN</a> &#x548C; <a href="http://toddmotto.com/es6-arrow-functions-syntaxes-and-lexical-scoping/" target="_blank">ES6 arrow functions, syntax and lexical scoping</a>&#xFF09;&#xFF0C;&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#x90FD;&#x80FD;&#x6EE1;&#x8DB3;&#x4F60;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x800C;&#x4E14;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x66F4;&#x4E3A;&#x7B80;&#x6D01;&#x3002;</p>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x4E0D;&#xFF1F;&#x5982;&#x679C;&#x4F60;&#x6709;&#x4E00;&#x4E2A;&#x76F8;&#x5F53;&#x590D;&#x6742;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x4F60;&#x6216;&#x8BB8;&#x53EF;&#x4EE5;&#x628A;&#x903B;&#x8F91;&#x90E8;&#x5206;&#x8F6C;&#x79FB;&#x5230;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E0A;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">*</span> x
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">*</span> x
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#8.2">8.2</a> <a name="8.2"></a> &#x5982;&#x679C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x9002;&#x5408;&#x7528;&#x4E00;&#x884C;&#x5199;&#x51FA;&#x5E76;&#x4E14;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x90A3;&#x5C31;&#x628A;&#x82B1;&#x62EC;&#x53F7;&#x3001;&#x5706;&#x62EC;&#x53F7;&#x548C; <code>return</code> &#x90FD;&#x7701;&#x7565;&#x6389;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x662F;&#xFF0C;&#x90A3;&#x5C31;&#x4E0D;&#x8981;&#x7701;&#x7565;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8BED;&#x6CD5;&#x7CD6;&#x3002;&#x5728;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#x4E2D;&#x53EF;&#x8BFB;&#x6027;&#x5F88;&#x9AD8;&#x3002;</p>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x4E0D;&#xFF1F;&#x5F53;&#x4F60;&#x6253;&#x7B97;&#x56DE;&#x4F20;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x65F6;&#x5019;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// good</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>x <span class="token operator">=</span><span class="token operator">&gt;</span> x <span class="token operator">*</span> x<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token punctuation">(</span>total<span class="token punctuation">,</span> n<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> total <span class="token operator">+</span> n
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<p><a name="constructors"></a></p>
<h2 id="&#x6784;&#x9020;&#x5668;"><a name="&#x6784;&#x9020;&#x5668;" class="plugin-anchor" href="#&#x6784;&#x9020;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6784;&#x9020;&#x5668;</h2>
<ul>
<li><p><a href="#9.1">9.1</a> <a name="9.1"></a> &#x603B;&#x662F;&#x4F7F;&#x7528; <code>class</code>&#x3002;&#x907F;&#x514D;&#x76F4;&#x63A5;&#x64CD;&#x4F5C; <code>prototype</code> &#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;? &#x56E0;&#x4E3A; <code>class</code> &#x8BED;&#x6CD5;&#x66F4;&#x4E3A;&#x7B80;&#x6D01;&#x66F4;&#x6613;&#x8BFB;&#x3002;</p>
</blockquote>
<p>```javascript
// bad
function Queue(contents = []) {
  this._queue = [...contents]
}
Queue.prototype.pop = function() {
  const value = this._queue[0]
  this._queue.splice(0, 1)
  return value
}</p>
</li>
</ul>
<pre class="language-"><code>// good
class Queue {
  constructor(contents = []) {
    this._queue = [...contents]
  }
  pop() {
    const value = this._queue[0]
    this._queue.splice(0, 1)
    return value
  }
}
```
</code></pre><ul>
<li><p><a href="#9.2">9.2</a> <a name="9.2"></a> &#x4F7F;&#x7528; <code>extends</code> &#x7EE7;&#x627F;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A; <code>extends</code> &#x662F;&#x4E00;&#x4E2A;&#x5185;&#x5EFA;&#x7684;&#x539F;&#x578B;&#x7EE7;&#x627F;&#x65B9;&#x6CD5;&#x5E76;&#x4E14;&#x4E0D;&#x4F1A;&#x7834;&#x574F; <code>instanceof</code>&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> inherits <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&apos;inherits&apos;</span><span class="token punctuation">)</span>
<span class="token keyword">function</span> <span class="token function">PeekableQueue</span><span class="token punctuation">(</span>contents<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  Queue<span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> contents<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">inherits</span><span class="token punctuation">(</span>PeekableQueue<span class="token punctuation">,</span> Queue<span class="token punctuation">)</span>
PeekableQueue<span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>peek <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_queue<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">class</span> <span class="token class-name">PeekableQueue</span> <span class="token keyword">extends</span> <span class="token class-name">Queue</span> <span class="token punctuation">{</span>
  <span class="token function">peek</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_queue<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#9.3">9.3</a> <a name="9.3"></a> &#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE; <code>this</code> &#x6765;&#x5E2E;&#x52A9;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
Jedi<span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>jump <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>jumping <span class="token operator">=</span> <span class="token boolean">true</span>
  <span class="token keyword">return</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>

Jedi<span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>setHeight <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span>height<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>height <span class="token operator">=</span> height
<span class="token punctuation">}</span>

<span class="token keyword">const</span> luke <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Jedi</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
luke<span class="token punctuation">.</span><span class="token function">jump</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; true</span>
luke<span class="token punctuation">.</span><span class="token function">setHeight</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; undefined</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">class</span> <span class="token class-name">Jedi</span> <span class="token punctuation">{</span>
  <span class="token function">jump</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>jumping <span class="token operator">=</span> <span class="token boolean">true</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span>
  <span class="token punctuation">}</span>

  <span class="token function">setHeight</span><span class="token punctuation">(</span>height<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>height <span class="token operator">=</span> height
    <span class="token keyword">return</span> <span class="token keyword">this</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">const</span> luke <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Jedi</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

luke<span class="token punctuation">.</span><span class="token function">jump</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">setHeight</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<ul>
<li><p><a href="#9.4">9.4</a> <a name="9.4"></a> &#x53EF;&#x4EE5;&#x5199;&#x4E00;&#x4E2A;&#x81EA;&#x5B9A;&#x4E49;&#x7684; <code>toString()</code> &#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x8981;&#x786E;&#x4FDD;&#x5B83;&#x80FD;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#x5E76;&#x4E14;&#x4E0D;&#x4F1A;&#x5F15;&#x8D77;&#x526F;&#x4F5C;&#x7528;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">class</span> <span class="token class-name">Jedi</span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span>options <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> options<span class="token punctuation">.</span>name <span class="token operator">||</span> <span class="token string">&apos;no name&apos;</span>
  <span class="token punctuation">}</span>

  <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>name
  <span class="token punctuation">}</span>

  <span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token template-string"><span class="token string">`Jedi - </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<p><a name="modules"></a></p>
<h2 id="&#x6A21;&#x5757;"><a name="&#x6A21;&#x5757;" class="plugin-anchor" href="#&#x6A21;&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6A21;&#x5757;</h2>
<ul>
<li><p><a href="#10.1">10.1</a> <a name="10.1"></a> &#x603B;&#x662F;&#x4F7F;&#x7528;&#x6A21;&#x7EC4; (<code>import</code>/<code>export</code>) &#x800C;&#x4E0D;&#x662F;&#x5176;&#x4ED6;&#x975E;&#x6807;&#x51C6;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x7F16;&#x8BD1;&#x4E3A;&#x4F60;&#x559C;&#x6B22;&#x7684;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x6A21;&#x5757;&#x5C31;&#x662F;&#x672A;&#x6765;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x8FC8;&#x5411;&#x672A;&#x6765;&#x5427;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> AirbnbStyleGuide <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&apos;./AirbnbStyleGuide&apos;</span><span class="token punctuation">)</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> AirbnbStyleGuide<span class="token punctuation">.</span>es6

<span class="token comment" spellcheck="true">// ok</span>
<span class="token keyword">import</span> AirbnbStyleGuide <span class="token keyword">from</span> <span class="token string">&apos;./AirbnbStyleGuide&apos;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> AirbnbStyleGuide<span class="token punctuation">.</span>es6

<span class="token comment" spellcheck="true">// best</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> es6 <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;./AirbnbStyleGuide&apos;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> es6
</code></pre>
</li>
<li><p><a href="#10.2">10.2</a> <a name="10.2"></a> &#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x901A;&#x914D;&#x7B26; import&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x6837;&#x80FD;&#x786E;&#x4FDD;&#x4F60;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4; export&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">import</span> <span class="token operator">*</span> <span class="token keyword">as</span> AirbnbStyleGuide <span class="token keyword">from</span> <span class="token string">&apos;./AirbnbStyleGuide&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">import</span> AirbnbStyleGuide <span class="token keyword">from</span> <span class="token string">&apos;./AirbnbStyleGuide&apos;</span>
</code></pre>
</li>
<li><p><a href="#10.3">10.3</a> <a name="10.3"></a>&#x4E0D;&#x8981;&#x4ECE; import &#x4E2D;&#x76F4;&#x63A5; export&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x867D;&#x7136;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x7B80;&#x6D01;&#x660E;&#x4E86;&#xFF0C;&#x4F46;&#x8BA9; import &#x548C; export &#x5404;&#x53F8;&#x5176;&#x804C;&#x8BA9;&#x4E8B;&#x60C5;&#x80FD;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token comment" spellcheck="true">// filename es6.js</span>
<span class="token keyword">export</span> <span class="token punctuation">{</span> es6 <span class="token keyword">as</span> <span class="token keyword">default</span> <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;./airbnbStyleGuide&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token comment" spellcheck="true">// filename es6.js</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> es6 <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;./AirbnbStyleGuide&apos;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> es6
</code></pre>
</li>
</ul>
<p><a name="iterators-and-generators"></a></p>
<h2 id="iterators-and-generators"><a name="iterators-and-generators" class="plugin-anchor" href="#iterators-and-generators"><i class="fa fa-link" aria-hidden="true"></i></a>Iterators and Generators</h2>
<ul>
<li><p><a href="#11.1">11.1</a> <a name="11.1"></a> &#x4E0D;&#x8981;&#x4F7F;&#x7528; iterators&#x3002;&#x4F7F;&#x7528;&#x9AD8;&#x9636;&#x51FD;&#x6570;&#x4F8B;&#x5982; <code>map()</code> &#x548C; <code>reduce()</code> &#x66FF;&#x4EE3; <code>for-of</code>&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x52A0;&#x5F3A;&#x4E86;&#x6211;&#x4EEC;&#x4E0D;&#x53D8;&#x7684;&#x89C4;&#x5219;&#x3002;&#x5904;&#x7406;&#x7EAF;&#x51FD;&#x6570;&#x7684;&#x56DE;&#x8C03;&#x503C;&#x66F4;&#x6613;&#x8BFB;&#xFF0C;&#x8FD9;&#x6BD4;&#x5B83;&#x5E26;&#x6765;&#x7684;&#x526F;&#x4F5C;&#x7528;&#x66F4;&#x91CD;&#x8981;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> numbers <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">let</span> sum <span class="token operator">=</span> <span class="token number">0</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> num <span class="token keyword">of</span> numbers<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  sum <span class="token operator">+</span><span class="token operator">=</span> num
<span class="token punctuation">}</span>

sum <span class="token operator">===</span> <span class="token number">15</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">let</span> sum <span class="token operator">=</span> <span class="token number">0</span>
numbers<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span>num<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> sum <span class="token operator">+</span><span class="token operator">=</span> num<span class="token punctuation">)</span>
sum <span class="token operator">===</span> <span class="token number">15</span>

<span class="token comment" spellcheck="true">// best (use the functional force)</span>
<span class="token keyword">const</span> sum <span class="token operator">=</span> numbers<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token punctuation">(</span>total<span class="token punctuation">,</span> num<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> total <span class="token operator">+</span> num<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
sum <span class="token operator">===</span> <span class="token number">15</span>
</code></pre>
</li>
<li><p><a href="#11.2">11.2</a> <a name="11.2"></a> &#x73B0;&#x5728;&#x8FD8;&#x4E0D;&#x8981;&#x4F7F;&#x7528; generators&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x73B0;&#x5728;&#x8FD8;&#x6CA1;&#x6CD5;&#x5F88;&#x597D;&#x5730;&#x7F16;&#x8BD1;&#x5230; ES5&#x3002; (&#x8BD1;&#x8005;&#x6CE8;&#xFF1A;&#x76EE;&#x524D;(2016/03) Chrome &#x548C; Node.js &#x7684;&#x7A33;&#x5B9A;&#x7248;&#x672C;&#x90FD;&#x5DF2;&#x652F;&#x6301; generators)</p>
</blockquote>
</li>
</ul>
<p><a name="properties"></a></p>
<h2 id="&#x5C5E;&#x6027;"><a name="&#x5C5E;&#x6027;" class="plugin-anchor" href="#&#x5C5E;&#x6027;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5C5E;&#x6027;</h2>
<ul>
<li><p><a href="#12.1">12.1</a> <a name="12.1"></a> &#x4F7F;&#x7528; <code>.</code> &#x6765;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> luke <span class="token operator">=</span> <span class="token punctuation">{</span>
  jedi<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
  age<span class="token punctuation">:</span> <span class="token number">28</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> isJedi <span class="token operator">=</span> luke<span class="token punctuation">[</span><span class="token string">&apos;jedi&apos;</span><span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> isJedi <span class="token operator">=</span> luke<span class="token punctuation">.</span>jedi
</code></pre>
</li>
<li><p><a href="#12.2">12.2</a> <a name="12.2"></a> &#x5F53;&#x901A;&#x8FC7;&#x53D8;&#x91CF;&#x8BBF;&#x95EE;&#x5C5E;&#x6027;&#x65F6;&#x4F7F;&#x7528;&#x4E2D;&#x62EC;&#x53F7; <code>[]</code>&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> luke <span class="token operator">=</span> <span class="token punctuation">{</span>
  jedi<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
  age<span class="token punctuation">:</span> <span class="token number">28</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token keyword">function</span> <span class="token function">getProp</span><span class="token punctuation">(</span>prop<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> luke<span class="token punctuation">[</span>prop<span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token keyword">const</span> isJedi <span class="token operator">=</span> <span class="token function">getProp</span><span class="token punctuation">(</span><span class="token string">&apos;jedi&apos;</span><span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<p><a name="variables"></a></p>
<h2 id="&#x53D8;&#x91CF;"><a name="&#x53D8;&#x91CF;" class="plugin-anchor" href="#&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x53D8;&#x91CF;</h2>
<ul>
<li><p><a href="#13.1">13.1</a> <a name="13.1"></a> &#x4E00;&#x76F4;&#x4F7F;&#x7528; <code>const</code> &#x6765;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x8FD9;&#x6837;&#x505A;&#x5C31;&#x4F1A;&#x4EA7;&#x751F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x907F;&#x514D;&#x5168;&#x5C40;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x6C61;&#x67D3;&#x3002;<a href="http://www.wikiwand.com/en/Captain_Planet" target="_blank">&#x5730;&#x7403;&#x961F;&#x957F;</a>&#x5DF2;&#x7ECF;&#x8B66;&#x544A;&#x8FC7;&#x6211;&#x4EEC;&#x4E86;&#x3002;&#xFF08;&#x8BD1;&#x6CE8;&#xFF1A;&#x5168;&#x5C40;&#xFF0C;global &#x4EA6;&#x6709;&#x5168;&#x7403;&#x7684;&#x610F;&#x601D;&#x3002;&#x5730;&#x7403;&#x961F;&#x957F;&#x7684;&#x8D23;&#x4EFB;&#x662F;&#x4FDD;&#x536B;&#x5730;&#x7403;&#x73AF;&#x5883;&#xFF0C;&#x6240;&#x4EE5;&#x4ED6;&#x8B66;&#x544A;&#x6211;&#x4EEC;&#x4E0D;&#x8981;&#x9020;&#x6210;&#x300C;&#x5168;&#x7403;&#x300D;&#x6C61;&#x67D3;&#x3002;&#xFF09;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
superPower <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SuperPower</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> superPower <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SuperPower</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#13.2">13.2</a> <a name="13.2"></a> &#x4F7F;&#x7528; <code>const</code> &#x58F0;&#x660E;&#x6BCF;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x589E;&#x52A0;&#x65B0;&#x53D8;&#x91CF;&#x5C06;&#x53D8;&#x7684;&#x66F4;&#x52A0;&#x5BB9;&#x6613;&#xFF0C;&#x800C;&#x4E14;&#x4F60;&#x6C38;&#x8FDC;&#x4E0D;&#x7528;&#x518D;&#x62C5;&#x5FC3;&#x8C03;&#x6362;&#x9519; <code>` &#x8DDF;</code>,`&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    goSportsTeam <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
    dragonball <span class="token operator">=</span> <span class="token string">&apos;z&apos;</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token comment" spellcheck="true">// (compare to above, and try to spot the mistake)</span>
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    goSportsTeam <span class="token operator">=</span> <span class="token boolean">true</span>
    dragonball <span class="token operator">=</span> <span class="token string">&apos;z&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> goSportsTeam <span class="token operator">=</span> <span class="token boolean">true</span>
<span class="token keyword">const</span> dragonball <span class="token operator">=</span> <span class="token string">&apos;z&apos;</span>
</code></pre>
</li>
<li><p><a href="#13.3">13.3</a> <a name="13.3"></a> &#x5C06;&#x6240;&#x6709;&#x7684; <code>const</code> &#x548C; <code>let</code> &#x5206;&#x7EC4;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x5F53;&#x4F60;&#x9700;&#x8981;&#x628A;&#x5DF2;&#x8D4B;&#x503C;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x7ED9;&#x672A;&#x8D4B;&#x503C;&#x53D8;&#x91CF;&#x65F6;&#x975E;&#x5E38;&#x6709;&#x7528;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">let</span> i<span class="token punctuation">,</span> len<span class="token punctuation">,</span> dragonball<span class="token punctuation">,</span>
    items <span class="token operator">=</span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    goSportsTeam <span class="token operator">=</span> <span class="token boolean">true</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">let</span> i
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">let</span> dragonball
<span class="token keyword">const</span> goSportsTeam <span class="token operator">=</span> <span class="token boolean">true</span>
<span class="token keyword">let</span> len

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> goSportsTeam <span class="token operator">=</span> <span class="token boolean">true</span>
<span class="token keyword">const</span> items <span class="token operator">=</span> <span class="token function">getItems</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">let</span> dragonball
<span class="token keyword">let</span> i
<span class="token keyword">let</span> length
</code></pre>
</li>
<li><p><a href="#13.4">13.4</a> <a name="13.4"></a> &#x5728;&#x4F60;&#x9700;&#x8981;&#x7684;&#x5730;&#x65B9;&#x7ED9;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#xFF0C;&#x4F46;&#x8BF7;&#x628A;&#x5B83;&#x4EEC;&#x653E;&#x5728;&#x4E00;&#x4E2A;&#x5408;&#x7406;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;<code>let</code> &#x548C; <code>const</code> &#x662F;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x800C;&#x4E0D;&#x662F;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;doing stuff..&apos;</span><span class="token punctuation">)</span>

  <span class="token comment" spellcheck="true">//..other stuff..</span>

  <span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  <span class="token keyword">if</span> <span class="token punctuation">(</span>name <span class="token operator">===</span> <span class="token string">&apos;test&apos;</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token boolean">false</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">return</span> name
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad - unnecessary function call</span>
<span class="token keyword">function</span><span class="token punctuation">(</span>hasName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>hasName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token boolean">false</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setFirstName</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>

  <span class="token keyword">return</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span><span class="token punctuation">(</span>hasName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>hasName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token boolean">false</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setFirstName</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>

  <span class="token keyword">return</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<p><a name="hoisting"></a></p>
<h2 id="hoisting"><a name="hoisting" class="plugin-anchor" href="#hoisting"><i class="fa fa-link" aria-hidden="true"></i></a>Hoisting</h2>
<ul>
<li><p><a href="#14.1">14.1</a> <a name="14.1"></a> <code>var</code> &#x58F0;&#x660E;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x81F3;&#x8BE5;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x9876;&#x90E8;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x8D4B;&#x503C;&#x4E0D;&#x4F1A;&#x63D0;&#x5347;&#x3002;<code>let</code> &#x548C; <code>const</code> &#x88AB;&#x8D4B;&#x4E88;&#x4E86;&#x4E00;&#x79CD;&#x79F0;&#x4E3A;&#x300C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let" target="_blank">&#x6682;&#x65F6;&#x6027;&#x6B7B;&#x533A;&#xFF08;Temporal Dead Zones, TDZ&#xFF09;</a>&#x300D;&#x7684;&#x6982;&#x5FF5;&#x3002;&#x8FD9;&#x5BF9;&#x4E8E;&#x4E86;&#x89E3;&#x4E3A;&#x4EC0;&#x4E48; <a href="http://es-discourse.com/t/why-typeof-is-no-longer-safe/15" target="_blank">type of &#x4E0D;&#x518D;&#x5B89;&#x5168;</a>&#x76F8;&#x5F53;&#x91CD;&#x8981;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// &#x6211;&#x4EEC;&#x77E5;&#x9053;&#x8FD9;&#x6837;&#x8FD0;&#x884C;&#x4E0D;&#x4E86; </span>
<span class="token comment" spellcheck="true">// &#xFF08;&#x5047;&#x8BBE; notDefined &#x4E0D;&#x662F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF09;</span>
<span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>notDefined<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; throws a ReferenceError</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// &#x7531;&#x4E8E;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x7684;&#x539F;&#x56E0;&#xFF0C;</span>
<span class="token comment" spellcheck="true">// &#x5728;&#x5F15;&#x7528;&#x53D8;&#x91CF;&#x540E;&#x518D;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x662F;&#x53EF;&#x4EE5;&#x8FD0;&#x884C;&#x7684;&#x3002;</span>
<span class="token comment" spellcheck="true">// &#x6CE8;&#xFF1A;&#x53D8;&#x91CF;&#x7684;&#x8D4B;&#x503C; `true` &#x4E0D;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x3002;</span>
<span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>declaredButNotAssigned<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; undefined</span>
  <span class="token keyword">var</span> declaredButNotAssigned <span class="token operator">=</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// &#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x628A;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x63D0;&#x5347;&#x5230;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x9876;&#x5C42;&#xFF0C;</span>
<span class="token comment" spellcheck="true">// &#x8FD9;&#x610F;&#x5473;&#x7740;&#x6211;&#x4EEC;&#x7684;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x6539;&#x5199;&#x6210;&#x8FD9;&#x6837;&#xFF1A;</span>
<span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">let</span> declaredButNotAssigned
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>declaredButNotAssigned<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; undefined</span>
  declaredButNotAssigned <span class="token operator">=</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// &#x4F7F;&#x7528; const &#x548C; let</span>
<span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>declaredButNotAssigned<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; throws a ReferenceError</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> declaredButNotAssigned<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; throws a ReferenceError</span>
  <span class="token keyword">const</span> declaredButNotAssigned <span class="token operator">=</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#14.2">14.2</a> <a name="14.2"></a> &#x533F;&#x540D;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#xFF0C;&#x4F46;&#x51FD;&#x6570;&#x5185;&#x5BB9;&#x5E76;&#x4E0D;&#x4F1A;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>anonymous<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; undefined</span>

  <span class="token function">anonymous</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; TypeError anonymous is not a function</span>

  <span class="token keyword">var</span> anonymous <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;anonymous function expression&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#14.3">14.3</a> <a name="14.3"></a> &#x547D;&#x540D;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#xFF0C;&#x4F46;&#x51FD;&#x6570;&#x540D;&#x548C;&#x51FD;&#x6570;&#x51FD;&#x6570;&#x5185;&#x5BB9;&#x5E76;&#x4E0D;&#x4F1A;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>named<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; undefined</span>

  <span class="token function">named</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; TypeError named is not a function</span>

  <span class="token function">superPower</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; ReferenceError superPower is not defined</span>

  <span class="token keyword">var</span> named <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token function">superPower</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Flying&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// the same is true when the function name</span>
<span class="token comment" spellcheck="true">// is the same as the variable name.</span>
<span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>named<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; undefined</span>

  <span class="token function">named</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; TypeError named is not a function</span>

  <span class="token keyword">var</span> named <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token function">named</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;named&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#14.4">14.4</a> <a name="14.4"></a> &#x51FD;&#x6570;&#x58F0;&#x660E;&#x7684;&#x540D;&#x79F0;&#x548C;&#x51FD;&#x6570;&#x4F53;&#x90FD;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">function</span> <span class="token function">example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">superPower</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// =&gt; Flying</span>

  <span class="token keyword">function</span> <span class="token function">superPower</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Flying&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p>&#x60F3;&#x4E86;&#x89E3;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#xFF0C;&#x53C2;&#x8003; <a href="http://www.adequatelygood.com/" target="_blank">Ben Cherry</a> &#x7684; <a href="http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting" target="_blank">JavaScript Scoping &amp; Hoisting</a>&#x3002;</p>
</li>
</ul>
<p><a name="comparison-operators--equality"></a></p>
<h2 id="&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;"><a name="&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;" class="plugin-anchor" href="#&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;--&#x7B49;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26; &amp; &#x7B49;&#x53F7;</h2>
<ul>
<li><a href="#15.1">15.1</a> <a name="15.1"></a> &#x4F18;&#x5148;&#x4F7F;&#x7528; <code>===</code> &#x548C; <code>!==</code> &#x800C;&#x4E0D;&#x662F; <code>==</code> &#x548C; <code>!=</code>.</li>
<li><p><a href="#15.2">15.2</a> <a name="15.2"></a> &#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x4F8B;&#x5982; <code>if</code> &#x8BED;&#x53E5;&#x901A;&#x8FC7;&#x62BD;&#x8C61;&#x65B9;&#x6CD5; <code>ToBoolean</code> &#x5F3A;&#x5236;&#x8BA1;&#x7B97;&#x5B83;&#x4EEC;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x5E76;&#x4E14;&#x603B;&#x662F;&#x9075;&#x5B88;&#x4E0B;&#x9762;&#x7684;&#x89C4;&#x5219;&#xFF1A;</p>
<ul>
<li><strong>&#x5BF9;&#x8C61;</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>true</strong></li>
<li><strong>Undefined</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong></li>
<li><strong>Null</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong></li>
<li><strong>&#x5E03;&#x5C14;&#x503C;</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>&#x5E03;&#x5C14;&#x7684;&#x503C;</strong></li>
<li><strong>&#x6570;&#x5B57;</strong> &#x5982;&#x679C;&#x662F; <strong>+0&#x3001;-0&#x3001;&#x6216; NaN</strong> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong>, &#x5426;&#x5219;&#x4E3A; <strong>true</strong></li>
<li><strong>&#x5B57;&#x7B26;&#x4E32;</strong> &#x5982;&#x679C;&#x662F;&#x7A7A;&#x5B57;&#x7B26;&#x4E32; <code>&apos;&apos;</code> &#x88AB;&#x8BA1;&#x7B97;&#x4E3A; <strong>false</strong>&#xFF0C;&#x5426;&#x5219;&#x4E3A; <strong>true</strong></li>
</ul>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// true</span>
  <span class="token comment" spellcheck="true">// An array is an object, objects evaluate to true</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#15.3">15.3</a> <a name="15.3"></a> &#x4F7F;&#x7528;&#x7B80;&#x5199;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>name <span class="token operator">!==</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>collection<span class="token punctuation">.</span>length <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>collection<span class="token punctuation">.</span>length<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#15.4">15.4</a> <a name="15.4"></a> &#x60F3;&#x4E86;&#x89E3;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#xFF0C;&#x53C2;&#x8003; Angus Croll &#x7684; <a href="http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108" target="_blank">Truth Equality and JavaScript</a>&#x3002;</p>
</li>
</ul>
<p><a name="blocks"></a></p>
<h2 id="&#x4EE3;&#x7801;&#x5757;"><a name="&#x4EE3;&#x7801;&#x5757;" class="plugin-anchor" href="#&#x4EE3;&#x7801;&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4EE3;&#x7801;&#x5757;</h2>
<ul>
<li><p><a href="#16.1">16.1</a> <a name="16.1"></a> &#x4F7F;&#x7528;&#x5927;&#x62EC;&#x53F7;&#x5305;&#x88F9;&#x6240;&#x6709;&#x7684;&#x591A;&#x884C;&#x4EE3;&#x7801;&#x5757;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>test<span class="token punctuation">)</span>
  <span class="token keyword">return</span> <span class="token boolean">false</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>test<span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token boolean">false</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>test<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">false</span> <span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#16.2">16.2</a> <a name="16.2"></a> &#x5982;&#x679C;&#x901A;&#x8FC7; <code>if</code> &#x548C; <code>else</code> &#x4F7F;&#x7528;&#x591A;&#x884C;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x628A; <code>else</code> &#x653E;&#x5728; <code>if</code> &#x4EE3;&#x7801;&#x5757;&#x5173;&#x95ED;&#x62EC;&#x53F7;&#x7684;&#x540C;&#x4E00;&#x884C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>test<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">thing1</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token function">thing2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token keyword">else</span> <span class="token punctuation">{</span>
  <span class="token function">thing3</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>test<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">thing1</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token function">thing2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
  <span class="token function">thing3</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<p><a name="comments"></a></p>
<h2 id="&#x6CE8;&#x91CA;"><a name="&#x6CE8;&#x91CA;" class="plugin-anchor" href="#&#x6CE8;&#x91CA;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6CE8;&#x91CA;</h2>
<ul>
<li><p><a href="#17.1">17.1</a> <a name="17.1"></a> &#x4F7F;&#x7528; <code>/** ... */</code> &#x4F5C;&#x4E3A;&#x591A;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5305;&#x542B;&#x63CF;&#x8FF0;&#x3001;&#x6307;&#x5B9A;&#x6240;&#x6709;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x548C;&#x503C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token comment" spellcheck="true">// make() returns a new element</span>
<span class="token comment" spellcheck="true">// based on the passed in tag name</span>
<span class="token comment" spellcheck="true">//</span>
<span class="token comment" spellcheck="true">// @param {String} tag</span>
<span class="token comment" spellcheck="true">// @return {Element} element</span>
<span class="token keyword">function</span> <span class="token function">make</span><span class="token punctuation">(</span>tag<span class="token punctuation">)</span> <span class="token punctuation">{</span>

  <span class="token comment" spellcheck="true">// ...stuff...</span>

  <span class="token keyword">return</span> element
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token comment" spellcheck="true">/**
 * make() returns a new element
 * based on the passed in tag name
 *
 * @param {String} tag
 * @return {Element} element
 */</span>
<span class="token keyword">function</span> <span class="token function">make</span><span class="token punctuation">(</span>tag<span class="token punctuation">)</span> <span class="token punctuation">{</span>

  <span class="token comment" spellcheck="true">// ...stuff...</span>

  <span class="token keyword">return</span> element
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#17.2">17.2</a> <a name="17.2"></a> &#x4F7F;&#x7528; <code>//</code> &#x4F5C;&#x4E3A;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5728;&#x8BC4;&#x8BBA;&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#x53E6;&#x8D77;&#x4E00;&#x884C;&#x4F7F;&#x7528;&#x5355;&#x884C;&#x6CE8;&#x91CA;&#x3002;&#x5728;&#x6CE8;&#x91CA;&#x524D;&#x63D2;&#x5165;&#x7A7A;&#x884C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> active <span class="token operator">=</span> <span class="token boolean">true</span>  <span class="token comment" spellcheck="true">// is current tab</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token comment" spellcheck="true">// is current tab</span>
<span class="token keyword">const</span> active <span class="token operator">=</span> <span class="token boolean">true</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;fetching type...&apos;</span><span class="token punctuation">)</span>
  <span class="token comment" spellcheck="true">// set the default type to &apos;no type&apos;</span>
  <span class="token keyword">const</span> type <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_type <span class="token operator">||</span> <span class="token string">&apos;no type&apos;</span>

  <span class="token keyword">return</span> type
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;fetching type...&apos;</span><span class="token punctuation">)</span>

  <span class="token comment" spellcheck="true">// set the default type to &apos;no type&apos;</span>
  <span class="token keyword">const</span> type <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_type <span class="token operator">||</span> <span class="token string">&apos;no type&apos;</span>

  <span class="token keyword">return</span> type
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#17.3">17.3</a> <a name="17.3"></a> &#x7ED9;&#x6CE8;&#x91CA;&#x589E;&#x52A0; <code>FIXME</code> &#x6216; <code>TODO</code> &#x7684;&#x524D;&#x7F00;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x5176;&#x4ED6;&#x5F00;&#x53D1;&#x8005;&#x5FEB;&#x901F;&#x4E86;&#x89E3;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x9700;&#x8981;&#x590D;&#x67E5;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6216;&#x662F;&#x7ED9;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x529F;&#x80FD;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x89E3;&#x51B3;&#x65B9;&#x5F0F;&#x3002;&#x8FD9;&#x5C06;&#x6709;&#x522B;&#x4E8E;&#x5E38;&#x89C1;&#x7684;&#x6CE8;&#x91CA;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x662F;&#x53EF;&#x64CD;&#x4F5C;&#x7684;&#x3002;&#x4F7F;&#x7528; <code>FIXME -- need to figure this out</code> &#x6216;&#x8005; <code>TODO -- need to implement</code>&#x3002;</p>
</li>
<li><p><a href="#17.4">17.4</a> <a name="17.4"></a> &#x4F7F;&#x7528; <code>// FIXME</code>: &#x6807;&#x6CE8;&#x95EE;&#x9898;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">class</span> <span class="token class-name">Calculator</span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">// FIXME: shouldn&apos;t use a global here</span>
    total <span class="token operator">=</span> <span class="token number">0</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#17.5">17.5</a> <a name="17.5"></a> &#x4F7F;&#x7528; <code>// TODO</code>: &#x6807;&#x6CE8;&#x95EE;&#x9898;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x5F0F;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">class</span> <span class="token class-name">Calculator</span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">// TODO: total should be configurable by an options param</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>total <span class="token operator">=</span> <span class="token number">0</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<p><a name="whitespace"></a></p>
<h2 id="&#x7A7A;&#x767D;"><a name="&#x7A7A;&#x767D;" class="plugin-anchor" href="#&#x7A7A;&#x767D;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7A7A;&#x767D;</h2>
<ul>
<li><p><a href="#18.1">18.1</a> <a name="18.1"></a> &#x4F7F;&#x7528; 2 &#x4E2A;&#x7A7A;&#x683C;&#x4F5C;&#x4E3A;&#x7F29;&#x8FDB;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
&#x2219;&#x2219;&#x2219;&#x2219;<span class="token keyword">const</span> name
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
&#x2219;<span class="token keyword">const</span> name
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
&#x2219;&#x2219;<span class="token keyword">const</span> name
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#18.2">18.2</a> <a name="18.2"></a> &#x5728;&#x82B1;&#x62EC;&#x53F7;&#x524D;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;test&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;test&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
dog<span class="token punctuation">.</span><span class="token keyword">set</span><span class="token punctuation">(</span><span class="token string">&apos;attr&apos;</span><span class="token punctuation">,</span><span class="token punctuation">{</span>
  age<span class="token punctuation">:</span> <span class="token string">&apos;1 year&apos;</span><span class="token punctuation">,</span>
  breed<span class="token punctuation">:</span> <span class="token string">&apos;Bernese Mountain Dog&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
dog<span class="token punctuation">.</span><span class="token keyword">set</span><span class="token punctuation">(</span><span class="token string">&apos;attr&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  age<span class="token punctuation">:</span> <span class="token string">&apos;1 year&apos;</span><span class="token punctuation">,</span>
  breed<span class="token punctuation">:</span> <span class="token string">&apos;Bernese Mountain Dog&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#18.3">18.3</a> <a name="18.3"></a> &#x5728;&#x63A7;&#x5236;&#x8BED;&#x53E5;&#xFF08;<code>if</code>&#x3001;<code>while</code> &#x7B49;&#xFF09;&#x7684;&#x5C0F;&#x62EC;&#x53F7;&#x524D;&#x653E;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x3002;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x53CA;&#x58F0;&#x660E;&#x4E2D;&#xFF0C;&#x4E0D;&#x5728;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x5217;&#x8868;&#x524D;&#x52A0;&#x7A7A;&#x683C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span><span class="token punctuation">(</span>isJedi<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fight <span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>isJedi<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">fight</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> fight <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span>log <span class="token punctuation">(</span><span class="token string">&apos;Swooosh!&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">fight</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Swooosh!&apos;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#18.4">18.4</a> <a name="18.4"></a> &#x4F7F;&#x7528;&#x7A7A;&#x683C;&#x628A;&#x8FD0;&#x7B97;&#x7B26;&#x9694;&#x5F00;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> x<span class="token operator">=</span>y<span class="token operator">+</span><span class="token number">5</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> x <span class="token operator">=</span> y <span class="token operator">+</span> <span class="token number">5</span>
</code></pre>
</li>
<li><p><a href="#18.5">18.5</a> <a name="18.5"></a> &#x5728;&#x6587;&#x4EF6;&#x672B;&#x5C3E;&#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x7A7A;&#x884C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>global<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span>
</code></pre>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>global<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span>&#x21B5;
&#x21B5;
</code></pre>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// good</span>
<span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>global<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span>&#x21B5;
</code></pre>
</li>
<li><p><a href="#18.5">18.5</a> <a name="18.5"></a> &#x5728;&#x4F7F;&#x7528;&#x957F;&#x65B9;&#x6CD5;&#x94FE;&#x65F6;&#x8FDB;&#x884C;&#x7F29;&#x8FDB;&#x3002;&#x4F7F;&#x7528;&#x524D;&#x9762;&#x7684;&#x70B9; <code>.</code> &#x5F3A;&#x8C03;&#x8FD9;&#x662F;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x800C;&#x4E0D;&#x662F;&#x65B0;&#x8BED;&#x53E5;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;#items&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;.selected&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">highlight</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;.open&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">updateCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;#items&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>
  <span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;.selected&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>
    <span class="token function">highlight</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>
    <span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>
  <span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;.open&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>
    <span class="token function">updateCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;#items&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;.selected&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">highlight</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;.open&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">updateCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> leds <span class="token operator">=</span> stage<span class="token punctuation">.</span><span class="token function">selectAll</span><span class="token punctuation">(</span><span class="token string">&apos;.led&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">data</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">enter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&apos;svg:svg&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">(</span><span class="token string">&apos;led&apos;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token string">&apos;width&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span>radius <span class="token operator">+</span> margin<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&apos;svg:g&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token string">&apos;transform&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;translate(&apos;</span> <span class="token operator">+</span> <span class="token punctuation">(</span>radius <span class="token operator">+</span> margin<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&apos;,&apos;</span> <span class="token operator">+</span> <span class="token punctuation">(</span>radius <span class="token operator">+</span> margin<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&apos;)&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>tron<span class="token punctuation">.</span>led<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> leds <span class="token operator">=</span> stage<span class="token punctuation">.</span><span class="token function">selectAll</span><span class="token punctuation">(</span><span class="token string">&apos;.led&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">data</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">enter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&apos;svg:svg&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">classed</span><span class="token punctuation">(</span><span class="token string">&apos;led&apos;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token string">&apos;width&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span>radius <span class="token operator">+</span> margin<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&apos;svg:g&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token string">&apos;transform&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;translate(&apos;</span> <span class="token operator">+</span> <span class="token punctuation">(</span>radius <span class="token operator">+</span> margin<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&apos;,&apos;</span> <span class="token operator">+</span> <span class="token punctuation">(</span>radius <span class="token operator">+</span> margin<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&apos;)&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>tron<span class="token punctuation">.</span>led<span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#18.6">18.6</a> <a name="18.6"></a> &#x5728;&#x5757;&#x672B;&#x548C;&#x65B0;&#x8BED;&#x53E5;&#x524D;&#x63D2;&#x5165;&#x7A7A;&#x884C;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>foo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> bar
<span class="token punctuation">}</span>
<span class="token keyword">return</span> baz

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>foo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> bar
<span class="token punctuation">}</span>

<span class="token keyword">return</span> baz

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">bar</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
<span class="token keyword">return</span> obj

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token function">bar</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token keyword">return</span> obj
</code></pre>
</li>
</ul>
<p><a name="commas"></a></p>
<h2 id="&#x9017;&#x53F7;"><a name="&#x9017;&#x53F7;" class="plugin-anchor" href="#&#x9017;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x9017;&#x53F7;</h2>
<ul>
<li><p><a href="#19.1">19.1</a> <a name="19.1"></a> &#x884C;&#x9996;&#x9017;&#x53F7;&#xFF1A;<strong>&#x4E0D;&#x9700;&#x8981;</strong>&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> story <span class="token operator">=</span> <span class="token punctuation">[</span>
    once
  <span class="token punctuation">,</span> upon
  <span class="token punctuation">,</span> aTime
<span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> story <span class="token operator">=</span> <span class="token punctuation">[</span>
  once<span class="token punctuation">,</span>
  upon<span class="token punctuation">,</span>
  aTime<span class="token punctuation">,</span>
<span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> hero <span class="token operator">=</span> <span class="token punctuation">{</span>
    firstName<span class="token punctuation">:</span> <span class="token string">&apos;Ada&apos;</span>
  <span class="token punctuation">,</span> lastName<span class="token punctuation">:</span> <span class="token string">&apos;Lovelace&apos;</span>
  <span class="token punctuation">,</span> birthYear<span class="token punctuation">:</span> <span class="token number">1815</span>
  <span class="token punctuation">,</span> superPower<span class="token punctuation">:</span> <span class="token string">&apos;computers&apos;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> hero <span class="token operator">=</span> <span class="token punctuation">{</span>
  firstName<span class="token punctuation">:</span> <span class="token string">&apos;Ada&apos;</span><span class="token punctuation">,</span>
  lastName<span class="token punctuation">:</span> <span class="token string">&apos;Lovelace&apos;</span><span class="token punctuation">,</span>
  birthYear<span class="token punctuation">:</span> <span class="token number">1815</span><span class="token punctuation">,</span>
  superPower<span class="token punctuation">:</span> <span class="token string">&apos;computers&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#19.2">19.2</a> <a name="19.2"></a> &#x589E;&#x52A0;&#x7ED3;&#x5C3E;&#x7684;&#x9017;&#x53F7;: <strong>&#x9700;&#x8981;</strong>&#x3002;</p>
<blockquote>
<p>&#x4E3A;&#x4EC0;&#x4E48;? &#x8FD9;&#x4F1A;&#x8BA9; git diffs &#x66F4;&#x5E72;&#x51C0;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x50CF; babel &#x8FD9;&#x6837;&#x7684;&#x8F6C;&#x8BD1;&#x5668;&#x4F1A;&#x79FB;&#x9664;&#x7ED3;&#x5C3E;&#x591A;&#x4F59;&#x7684;&#x9017;&#x53F7;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x4F60;&#x4E0D;&#x5FC5;&#x62C5;&#x5FC3;&#x8001;&#x65E7;&#x6D4F;&#x89C8;&#x5668;&#x7684;<a href="es5/README.md#commas">&#x5C3E;&#x9017;&#x53F7;&#x95EE;&#x9898;</a>&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad - git diff without trailing comma</span>
<span class="token keyword">const</span> hero <span class="token operator">=</span> <span class="token punctuation">{</span>
     firstName<span class="token punctuation">:</span> <span class="token string">&apos;Florence&apos;</span><span class="token punctuation">,</span>
<span class="token operator">-</span>    lastName<span class="token punctuation">:</span> <span class="token string">&apos;Nightingale&apos;</span>
<span class="token operator">+</span>    lastName<span class="token punctuation">:</span> <span class="token string">&apos;Nightingale&apos;</span><span class="token punctuation">,</span>
<span class="token operator">+</span>    inventorOf<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;coxcomb graph&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;modern nursing&apos;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good - git diff with trailing comma</span>
<span class="token keyword">const</span> hero <span class="token operator">=</span> <span class="token punctuation">{</span>
     firstName<span class="token punctuation">:</span> <span class="token string">&apos;Florence&apos;</span><span class="token punctuation">,</span>
     lastName<span class="token punctuation">:</span> <span class="token string">&apos;Nightingale&apos;</span><span class="token punctuation">,</span>
<span class="token operator">+</span>    inventorOf<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;coxcomb chart&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;modern nursing&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> hero <span class="token operator">=</span> <span class="token punctuation">{</span>
  firstName<span class="token punctuation">:</span> <span class="token string">&apos;Dana&apos;</span><span class="token punctuation">,</span>
  lastName<span class="token punctuation">:</span> <span class="token string">&apos;Scully&apos;</span>
<span class="token punctuation">}</span>

<span class="token keyword">const</span> heroes <span class="token operator">=</span> <span class="token punctuation">[</span>
  <span class="token string">&apos;Batman&apos;</span><span class="token punctuation">,</span>
  <span class="token string">&apos;Superman&apos;</span>
<span class="token punctuation">]</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> hero <span class="token operator">=</span> <span class="token punctuation">{</span>
  firstName<span class="token punctuation">:</span> <span class="token string">&apos;Dana&apos;</span><span class="token punctuation">,</span>
  lastName<span class="token punctuation">:</span> <span class="token string">&apos;Scully&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

<span class="token keyword">const</span> heroes <span class="token operator">=</span> <span class="token punctuation">[</span>
  <span class="token string">&apos;Batman&apos;</span><span class="token punctuation">,</span>
  <span class="token string">&apos;Superman&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span>
</code></pre>
</li>
</ul>
<p><a name="semicolons"></a></p>
<h2 id="&#x5206;&#x53F7;"><a name="&#x5206;&#x53F7;" class="plugin-anchor" href="#&#x5206;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5206;&#x53F7;</h2>
<ul>
<li><a href="#20.1">20.1</a> <a name="20.1"></a> <strong>&#x4E0D;&#x5F3A;&#x5236;&#x4F7F;&#x7528;&#x5206;&#x53F7; &#x63A8;&#x8350;&#x4E0D;&#x4F7F;&#x7528;&#x5206;&#x53F7;</strong> (&#x8DDF;Airbnb&#x5B98;&#x65B9;&#x4E0D;&#x81F4;) </li>
</ul>
<p><a name="type-casting--coercion"></a></p>
<h2 id="&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><a name="&#x7C7B;&#x578B;&#x8F6C;&#x6362;" class="plugin-anchor" href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7C7B;&#x578B;&#x8F6C;&#x6362;</h2>
<ul>
<li><a href="#21.1">21.1</a> <a name="21.1"></a> &#x5728;&#x8BED;&#x53E5;&#x5F00;&#x59CB;&#x65F6;&#x6267;&#x884C;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3002;</li>
<li><p><a href="#21.2">21.2</a> <a name="21.2"></a> &#x5B57;&#x7B26;&#x4E32;&#xFF1A;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">//  =&gt; this.reviewScore = 9</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> totalScore <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>reviewScore <span class="token operator">+</span> <span class="token string">&apos;&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> totalScore <span class="token operator">=</span> <span class="token function">String</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>reviewScore<span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#21.3">21.3</a> <a name="21.3"></a> &#x5BF9;&#x6570;&#x5B57;&#x4F7F;&#x7528; <code>parseInt</code> &#x8F6C;&#x6362;&#xFF0C;&#x5E76;&#x5E26;&#x4E0A;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x7684;&#x57FA;&#x6570;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> inputValue <span class="token operator">=</span> <span class="token string">&apos;4&apos;</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Number</span><span class="token punctuation">(</span>inputValue<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> <span class="token operator">+</span>inputValue

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> inputValue <span class="token operator">&gt;</span><span class="token operator">&gt;</span> <span class="token number">0</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>inputValue<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> <span class="token function">Number</span><span class="token punctuation">(</span>inputValue<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>inputValue<span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#21.4">21.4</a> <a name="21.4"></a> &#x5982;&#x679C;&#x56E0;&#x4E3A;&#x67D0;&#x4E9B;&#x539F;&#x56E0; parseInt &#x6210;&#x4E3A;&#x4F60;&#x6240;&#x505A;&#x7684;&#x4E8B;&#x7684;&#x74F6;&#x9888;&#x800C;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4F4D;&#x64CD;&#x4F5C;&#x89E3;&#x51B3;<a href="http://jsperf.com/coercion-vs-casting/3" target="_blank">&#x6027;&#x80FD;&#x95EE;&#x9898;</a>&#x65F6;&#xFF0C;&#x7559;&#x4E2A;&#x6CE8;&#x91CA;&#x8BF4;&#x6E05;&#x695A;&#x539F;&#x56E0;&#x548C;&#x4F60;&#x7684;&#x76EE;&#x7684;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// good</span>
<span class="token comment" spellcheck="true">/**
 * &#x4F7F;&#x7528; parseInt &#x5BFC;&#x81F4;&#x6211;&#x7684;&#x7A0B;&#x5E8F;&#x53D8;&#x6162;&#xFF0C;
 * &#x6539;&#x6210;&#x4F7F;&#x7528;&#x4F4D;&#x64CD;&#x4F5C;&#x8F6C;&#x6362;&#x6570;&#x5B57;&#x5FEB;&#x591A;&#x4E86;&#x3002;
 */</span>
<span class="token keyword">const</span> val <span class="token operator">=</span> inputValue <span class="token operator">&gt;</span><span class="token operator">&gt;</span> <span class="token number">0</span>
</code></pre>
</li>
<li><p><a href="#21.5">21.5</a> <a name="21.5"></a> <strong>&#x6CE8;:</strong> &#x5C0F;&#x5FC3;&#x4F7F;&#x7528;&#x4F4D;&#x64CD;&#x4F5C;&#x8FD0;&#x7B97;&#x7B26;&#x3002;&#x6570;&#x5B57;&#x4F1A;&#x88AB;&#x5F53;&#x6210; <a href="http://es5.github.io/#x4.3.19" target="_blank">64 &#x4F4D;&#x503C;</a>&#xFF0C;&#x4F46;&#x662F;&#x4F4D;&#x64CD;&#x4F5C;&#x8FD0;&#x7B97;&#x7B26;&#x603B;&#x662F;&#x8FD4;&#x56DE; 32 &#x4F4D;&#x7684;&#x6574;&#x6570;&#xFF08;<a href="http://es5.github.io/#x11.7" target="_blank">&#x53C2;&#x8003;</a>&#xFF09;&#x3002;&#x4F4D;&#x64CD;&#x4F5C;&#x5904;&#x7406;&#x5927;&#x4E8E; 32 &#x4F4D;&#x7684;&#x6574;&#x6570;&#x503C;&#x65F6;&#x8FD8;&#x4F1A;&#x5BFC;&#x81F4;&#x610F;&#x6599;&#x4E4B;&#x5916;&#x7684;&#x884C;&#x4E3A;&#x3002;<a href="https://github.com/airbnb/javascript/issues/109" target="_blank">&#x5173;&#x4E8E;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x8BA8;&#x8BBA;</a>&#x3002;&#x6700;&#x5927;&#x7684; 32 &#x4F4D;&#x6574;&#x6570;&#x662F; 2,147,483,647&#xFF1A;</p>
<pre class="language-"><code class="lang-javascript"><span class="token number">2147483647</span> <span class="token operator">&gt;</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token comment" spellcheck="true">//=&gt; 2147483647</span>
<span class="token number">2147483648</span> <span class="token operator">&gt;</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token comment" spellcheck="true">//=&gt; -2147483648</span>
<span class="token number">2147483649</span> <span class="token operator">&gt;</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token comment" spellcheck="true">//=&gt; -2147483647</span>
</code></pre>
</li>
<li><p><a href="#21.6">21.6</a> <a name="21.6"></a> &#x5E03;&#x5C14;:</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> age <span class="token operator">=</span> <span class="token number">0</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> hasAge <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Boolean</span><span class="token punctuation">(</span>age<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> hasAge <span class="token operator">=</span> <span class="token function">Boolean</span><span class="token punctuation">(</span>age<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> hasAge <span class="token operator">=</span> <span class="token operator">!</span><span class="token operator">!</span>age
</code></pre>
</li>
</ul>
<p><a name="naming-conventions"></a></p>
<h2 id="&#x547D;&#x540D;&#x89C4;&#x5219;"><a name="&#x547D;&#x540D;&#x89C4;&#x5219;" class="plugin-anchor" href="#&#x547D;&#x540D;&#x89C4;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x547D;&#x540D;&#x89C4;&#x5219;</h2>
<ul>
<li><p><a href="#22.1">22.1</a> <a name="22.1"></a> &#x907F;&#x514D;&#x5355;&#x5B57;&#x6BCD;&#x547D;&#x540D;&#x3002;&#x547D;&#x540D;&#x5E94;&#x5177;&#x5907;&#x63CF;&#x8FF0;&#x6027;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">q</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...stuff...</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">query</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ..stuff..</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#22.2">22.2</a> <a name="22.2"></a> &#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x5F0F;&#x547D;&#x540D;&#x5BF9;&#x8C61;&#x3001;&#x51FD;&#x6570;&#x548C;&#x5B9E;&#x4F8B;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> OBJEcttsssss <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">const</span> this_is_my_object <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">function</span> <span class="token function">c</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> thisIsMyObject <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">function</span> <span class="token function">thisIsMyFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#22.3">22.3</a> <a name="22.3"></a> &#x4F7F;&#x7528;&#x5E15;&#x65AF;&#x5361;&#x5F0F;&#x547D;&#x540D;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6216;&#x7C7B;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">user</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> options<span class="token punctuation">.</span>name
<span class="token punctuation">}</span>

<span class="token keyword">const</span> bad <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">user</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  name<span class="token punctuation">:</span> <span class="token string">&apos;nope&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">class</span> <span class="token class-name">User</span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> options<span class="token punctuation">.</span>name
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">const</span> good <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">User</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  name<span class="token punctuation">:</span> <span class="token string">&apos;yup&apos;</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#22.4">22.4</a> <a name="22.4"></a> &#x4F7F;&#x7528;&#x4E0B;&#x5212;&#x7EBF; <code>_</code> &#x5F00;&#x5934;&#x547D;&#x540D;&#x79C1;&#x6709;&#x5C5E;&#x6027;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>__firstName__ <span class="token operator">=</span> <span class="token string">&apos;Panda&apos;</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>firstName_ <span class="token operator">=</span> <span class="token string">&apos;Panda&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>_firstName <span class="token operator">=</span> <span class="token string">&apos;Panda&apos;</span>
</code></pre>
</li>
<li><p><a href="#22.5">22.5</a> <a name="22.5"></a> &#x522B;&#x4FDD;&#x5B58; <code>this</code> &#x7684;&#x5F15;&#x7528;&#x3002;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6216; Function#bind&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> self <span class="token operator">=</span> <span class="token keyword">this</span>
  <span class="token keyword">return</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> that <span class="token operator">=</span> <span class="token keyword">this</span>
  <span class="token keyword">return</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>that<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">foo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#22.6">22.6</a> <a name="22.6"></a> &#x5982;&#x679C;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x53EA;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x90A3;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x5FC5;&#x987B;&#x548C;&#x7C7B;&#x540D;&#x5B8C;&#x5168;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// file contents</span>
<span class="token keyword">class</span> <span class="token class-name">CheckBox</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// ...</span>
<span class="token punctuation">}</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> CheckBox

<span class="token comment" spellcheck="true">// in some other file</span>
<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">import</span> CheckBox <span class="token keyword">from</span> <span class="token string">&apos;./checkBox&apos;</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">import</span> CheckBox <span class="token keyword">from</span> <span class="token string">&apos;./check_box&apos;</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">import</span> CheckBox <span class="token keyword">from</span> <span class="token string">&apos;./CheckBox&apos;</span>
</code></pre>
</li>
<li><p><a href="#22.7">22.7</a> <a name="22.7"></a> &#x5F53;&#x4F60;&#x5BFC;&#x51FA;&#x9ED8;&#x8BA4;&#x7684;&#x51FD;&#x6570;&#x65F6;&#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x5F0F;&#x547D;&#x540D;&#x3002;&#x4F60;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x5FC5;&#x987B;&#x548C;&#x51FD;&#x6570;&#x540D;&#x5B8C;&#x5168;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">function</span> <span class="token function">makeStyleGuide</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> makeStyleGuide
</code></pre>
</li>
<li><p><a href="#22.8">22.8</a> <a name="22.8"></a> &#x5F53;&#x4F60;&#x5BFC;&#x51FA;&#x5355;&#x4F8B;&#x3001;&#x51FD;&#x6570;&#x5E93;&#x3001;&#x7A7A;&#x5BF9;&#x8C61;&#x65F6;&#x4F7F;&#x7528;&#x5E15;&#x65AF;&#x5361;&#x5F0F;&#x547D;&#x540D;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">const</span> AirbnbStyleGuide <span class="token operator">=</span> <span class="token punctuation">{</span>
  es6<span class="token punctuation">:</span> <span class="token punctuation">{</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> AirbnbStyleGuide
</code></pre>
</li>
</ul>
<p><a name="accessors"></a></p>
<h2 id="&#x5B58;&#x53D6;&#x5668;"><a name="&#x5B58;&#x53D6;&#x5668;" class="plugin-anchor" href="#&#x5B58;&#x53D6;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B58;&#x53D6;&#x5668;</h2>
<ul>
<li><a href="#23.1">23.1</a> <a name="23.1"></a> &#x5C5E;&#x6027;&#x7684;&#x5B58;&#x53D6;&#x51FD;&#x6570;&#x4E0D;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;</li>
<li><p><a href="#23.2">23.2</a> <a name="23.2"></a> &#x5982;&#x679C;&#x4F60;&#x9700;&#x8981;&#x5B58;&#x53D6;&#x51FD;&#x6570;&#x65F6;&#x4F7F;&#x7528; <code>getVal()</code> &#x548C; <code>setVal(&apos;hello&apos;)</code>&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
dragon<span class="token punctuation">.</span><span class="token function">age</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
dragon<span class="token punctuation">.</span><span class="token function">getAge</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// bad</span>
dragon<span class="token punctuation">.</span><span class="token function">age</span><span class="token punctuation">(</span><span class="token number">25</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
dragon<span class="token punctuation">.</span><span class="token function">setAge</span><span class="token punctuation">(</span><span class="token number">25</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#23.3">23.3</a> <a name="23.3"></a> &#x5982;&#x679C;&#x5C5E;&#x6027;&#x662F;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x4F7F;&#x7528; <code>isVal()</code> &#x6216; <code>hasVal()</code>&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>dragon<span class="token punctuation">.</span><span class="token function">age</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>dragon<span class="token punctuation">.</span><span class="token function">hasAge</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#23.4">23.4</a> <a name="23.4"></a> &#x521B;&#x5EFA; <code>get()</code> &#x548C; <code>set()</code> &#x51FD;&#x6570;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#xFF0C;&#x4F46;&#x8981;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">class</span> <span class="token class-name">Jedi</span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span>options <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> lightsaber <span class="token operator">=</span> options<span class="token punctuation">.</span>lightsaber <span class="token operator">||</span> <span class="token string">&apos;blue&apos;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token keyword">set</span><span class="token punctuation">(</span><span class="token string">&apos;lightsaber&apos;</span><span class="token punctuation">,</span> lightsaber<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">set</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> val<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> val
  <span class="token punctuation">}</span>

  <span class="token keyword">get</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">[</span>key<span class="token punctuation">]</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<p><a name="events"></a></p>
<h2 id="&#x4E8B;&#x4EF6;"><a name="&#x4E8B;&#x4EF6;" class="plugin-anchor" href="#&#x4E8B;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8B;&#x4EF6;</h2>
<ul>
<li><p><a href="#24.1">24.1</a> <a name="24.1"></a> &#x5F53;&#x7ED9;&#x4E8B;&#x4EF6;&#x9644;&#x52A0;&#x6570;&#x636E;&#x65F6;&#xFF08;&#x65E0;&#x8BBA;&#x662F; DOM &#x4E8B;&#x4EF6;&#x8FD8;&#x662F;&#x79C1;&#x6709;&#x4E8B;&#x4EF6;&#xFF09;&#xFF0C;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x54C8;&#x5E0C;&#x800C;&#x4E0D;&#x662F;&#x539F;&#x59CB;&#x503C;&#x3002;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x8BA9;&#x540E;&#x9762;&#x7684;&#x8D21;&#x732E;&#x8005;&#x589E;&#x52A0;&#x66F4;&#x591A;&#x6570;&#x636E;&#x5230;&#x4E8B;&#x4EF6;&#x6570;&#x636E;&#x800C;&#x65E0;&#x9700;&#x627E;&#x51FA;&#x5E76;&#x66F4;&#x65B0;&#x4E8B;&#x4EF6;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x5904;&#x7406;&#x5668;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4E0D;&#x597D;&#x7684;&#x5199;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trigger</span><span class="token punctuation">(</span><span class="token string">&apos;listingUpdated&apos;</span><span class="token punctuation">,</span> listing<span class="token punctuation">.</span>id<span class="token punctuation">)</span>

<span class="token operator">...</span>

<span class="token function">$</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">&apos;listingUpdated&apos;</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span>e<span class="token punctuation">,</span> listingId<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// do something with listingId</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<p>&#x66F4;&#x597D;&#x7684;&#x5199;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// good</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trigger</span><span class="token punctuation">(</span><span class="token string">&apos;listingUpdated&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> listingId <span class="token punctuation">:</span> listing<span class="token punctuation">.</span>id <span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token operator">...</span>

<span class="token function">$</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">&apos;listingUpdated&apos;</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span>e<span class="token punctuation">,</span> data<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment" spellcheck="true">// do something with data.listingId</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<h2 id="jquery"><a name="jquery" class="plugin-anchor" href="#jquery"><i class="fa fa-link" aria-hidden="true"></i></a>jQuery</h2>
<ul>
<li><p><a href="#25.1">25.1</a> <a name="25.1"></a> &#x4F7F;&#x7528; <code>$</code> &#x4F5C;&#x4E3A;&#x5B58;&#x50A8; jQuery &#x5BF9;&#x8C61;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x524D;&#x7F00;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">const</span> sidebar <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">const</span> $sidebar <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p><a href="#25.2">25.2</a> <a name="25.2"></a> &#x7F13;&#x5B58; jQuery &#x67E5;&#x8BE2;&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token keyword">function</span> <span class="token function">setSidebar</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  <span class="token comment" spellcheck="true">// ...stuff...</span>

  <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    <span class="token string">&apos;background-color&apos;</span><span class="token punctuation">:</span> <span class="token string">&apos;pink&apos;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token keyword">function</span> <span class="token function">setSidebar</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> $sidebar <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span>
  $sidebar<span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  <span class="token comment" spellcheck="true">// ...stuff...</span>

  $sidebar<span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    <span class="token string">&apos;background-color&apos;</span><span class="token punctuation">:</span> <span class="token string">&apos;pink&apos;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><a href="#25.3">25.3</a> <a name="25.3"></a> &#x5BF9; DOM &#x67E5;&#x8BE2;&#x4F7F;&#x7528;&#x5C42;&#x53E0; <code>$(&apos;.sidebar ul&apos;)</code> &#x6216; &#x7236;&#x5143;&#x7D20; &gt; &#x5B50;&#x5143;&#x7D20; <code>$(&apos;.sidebar &gt; ul&apos;)</code>&#x3002; <a href="http://jsperf.com/jquery-find-vs-context-sel/16" target="_blank">jsPerf</a></p>
</li>
<li><p><a href="#25.4">25.4</a> <a name="25.4"></a> &#x5BF9;&#x6709;&#x4F5C;&#x7528;&#x57DF;&#x7684; jQuery &#x5BF9;&#x8C61;&#x67E5;&#x8BE2;&#x4F7F;&#x7528; <code>find</code>&#x3002;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment" spellcheck="true">// bad</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;ul&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// bad</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;ul&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar ul&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&apos;.sidebar &gt; ul&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">// good</span>
$sidebar<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&apos;ul&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">hide</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
</li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; doc.ickeep.com 2017 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2017-03-10 21:07:01
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="3.JavaScript.html" class="navigation navigation-prev " aria-label="Previous page: 3.JavaScript">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5.vue规范.html" class="navigation navigation-next " aria-label="Next page: 5.vue规范">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"4.ESlint 检测规则说明","level":"2.4","depth":1,"next":{"title":"5.vue规范","level":"2.5","depth":1,"path":"2.前端规范/5.vue规范.md","ref":"2.前端规范/5.vue规范.md","articles":[]},"previous":{"title":"3.JavaScript","level":"2.3","depth":1,"path":"2.前端规范/3.JavaScript.md","ref":"2.前端规范/3.JavaScript.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","prism","-highlight","search-plus","tbfed-pagefooter","expandable-chapters-small","anchors","edit-link","diy-introduction","sitemap-general","livereload"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy doc.ickeep.com 2017","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"introduction-text":"开发说明","prism":{},"livereload":{},"sitemap-general":{"prefix":"https://doc.ickeep.com"},"fontsettings":{"theme":"white","family":"sans","size":2},"fontSettings":{"theme":"night","family":"sans","size":2},"diy-introduction":{},"favicon":{"shortcut":"/assets/img/favicon.ico","bookmark":"/assets/img/favicon.ico","appleTouch":"/assets/img/apple-touch-icon.png","appleTouchMore":{"120x120":"/assets/img/apple-touch-icon-120x120.png","180x180":"/assets/img/apple-touch-icon-180x180.png"}},"expandable-chapters-small":{},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","instapaper","instapaper"]},"edit-link":{"label":"编辑此页","base":"https://git.oschina.net/ickeep/dev-doc.git/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{},"search-plus":{}},"theme":"default","author":"i@ickeep.com","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.MD","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"邦德前端开发","language":"zh-hans","links":{"sidebar":{"邦德官网":"http://2017hcb.bond520.com/pc/index.html"}},"gitbook":"*","description":"邦德前端开发文档"},"file":{"path":"2.前端规范/4.ESlint检测规则说明.md","mtime":"2017-03-10T13:07:01.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-10T13:25:56.104Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

